#include "Menu.h"
#include "Model.h"
#include "Enum.h"

Menu::Menu()
{
	button[0].SetText("Play Game");
	button[0].SetPosition(50, 150);
	button[0].SetButtonID(GAME);
	button[1].SetText("Options");
	button[1].SetPosition(450, 150);
	button[1].SetButtonID(SYNCH);
	button[2].SetText("Credits");
	button[2].SetPosition(50, 300);
	button[2].SetButtonID(QUIT);

	justOpened = true;
}

void Menu::Open()
{
	//Sound
	soundToLoad.Music		= NO_MUSIC;
}

bool Menu::Update(XY mousePosition, bool clicked)
{	
	for(int i = 0; i < NUM_MENU_BUTTONS; ++i)
	{
		if	( button[i].MouseOver(mousePosition) )
		{
			if(clicked)
			{
				if(button[i].GetButtonID() == QUIT)
				{
					return false;
				}
				Model::getInstance()->changeState( button[i].GetButtonID() );
			}
		}
	}
	return true;
}

void Menu::Render(LostVector<DrawStruct>* draw, LostVector<SoundStruct>* sound)
{
	if(justOpened)
	{
		sound->add(soundToLoad);			//Add the music that was just initialized to the Sound Structure that was passed in
		justOpened = false;
	}

	//Background image
	objectToDraw.Tex		= MENU_BACKGROUND;
	objectToDraw.scale		= 0.5f;
	draw->add(objectToDraw);

	for(int i = 0; i < NUM_MENU_BUTTONS; ++i)
	{
		button[i].Draw(draw, sound);
	}
}

void Menu::Close()
{
	soundToLoad.Music = NO_MUSIC;
}